// pages/signedrecord.js
Page({
  mixins: [require('../../mixin/themeChanged')],

  /**
   * 页面的初始数据
   */
  data: {
    RequestSignList:'',
    inputShowed: false,
    inputVal: ""
  },

  //搜索框样式js
  showInput: function () {
    this.setData({
        inputShowed: true
    });
  },
  hideInput: function () {
    this.setData({
        inputVal: "",
        inputShowed: false
    });
  },
  clearInput: function () {
    this.setData({
        inputVal: ""
    });
  },
  inputTyping: function (e) {
    this.setData({
        inputVal: e.detail.value
    });
  },
  
  // 跳转到详情页面
  gotodetail: function (event) {
    var id = event.currentTarget.dataset.id;
    console.log("跳转的ID：",id);
    wx.navigateTo({
      url: '../signeddetail/signeddetail?id='+id,
    })
  },

  // 搜索功能实现方法
  search: function(inputVal){
    var that = this;
    var hg_id = 19721473;       //需要获取到当前护工的ID
    var condition = that.data.inputVal;       //获取搜索框输入信息
    if(condition=="" || condition==null ||condition=="undefined"){
      wx.showToast({
        title: '搜索内容为空！',
        icon:"none",
        duration:2000,
        mask:true
      })
    }else{
      if(isNaN(condition)){
        console.log("输入地址进行模糊搜索...");
        wx.request({
          url: 'http://localhost:8080/weChat_sign/weChat_findSignListByFuzzySearch?condition='+condition+'&hg_id='+hg_id,
          data:{
            condition:condition,
            hg_id:hg_id
          },
          method:'GET',
          header:{
            'content-type': 'application/json' // 默认值
          },
          success:function(res){
            var requestList = res.data;
            console.log("获取到数据：",requestList);
            if(requestList.length > 0){
              wx.showToast({
                title: '搜索成功！',
                icon:"success",
                duration:2000,
                mask:true
              })
              that.setData({
                RequestSignList:requestList
              })
            }else{
              wx.showToast({
                title: '找不到相关数据！',
                icon:"none",
                duration:2000,
                mask:true
              })
              that.setData({
                RequestSignList:''
              })
            }
          }
        })
      }else{
        console.log("输入老人ID模糊搜索...");
        wx.request({
          url: 'http://localhost:8080/weChat_sign/weChat_findSignListByLrFuzzySearch?lrCondition='+condition+'&hg_id='+hg_id,
          data:{
            lrCondition:condition,
            hg_id:hg_id
          },
          method:'GET',
          header:{
            'content-type': 'application/json' // 默认值
          },
          success:function(res){
            var requestList = res.data;
            console.log("获取到数据：",requestList);
            if(requestList.length > 0){
              wx.showToast({
                title: '搜索成功！',
                icon:"success",
                duration:2000,
                mask:true
              })
              that.setData({
                RequestSignList:requestList
              })
            }else{
              wx.showToast({
                title: '找不到相关数据！',
                icon:"none",
                duration:2000,
                mask:true
              })
              that.setData({
                RequestSignList:''
              })
            }
          }
        })
      };
      console.log("输入的搜索内容是：",condition);
    }
  },

  onLoad: function (options) {
    var that = this;
    var hg_id = 19721473;       //需要获取到当前护工的ID
    wx.request({
      url: 'http://localhost:8080/weChat_sign/weChat_findSignListByStaffId?hg_id='+hg_id,
      data:hg_id,
      method:'GET',
      header:{
        'content-type': 'application/json' // 默认值
      },
      success:function(res){
        if(res){
          var requestList = res.data;
          console.log("获取到数据：",requestList);
          that.setData({
            RequestSignList:requestList
          })
        }else{
          console.log("没有数据！")
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})